<template>
  <div class="card-container">

    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">车牌号码：</span>
      <el-input v-model="params.carNumber" clearable placeholder="请输入内容" class="search-main" @clear="getList"/>
      <span class="search-label">车主姓名：</span>
      <el-input v-model="params.personName" clearable placeholder="请输入内容" class="search-main" @clear="getList"/>
      <span class="search-label">状态：</span>
      <el-select  v-model="params.cardStatus">
        <el-option 
        v-for="item in paramsop" 
        :key="item.carid" 
        :value="item.carvalue" 
        :label="item.carname"/>
       
      </el-select>
      <el-button type="primary" class="search-btn"  @click="getList">查询</el-button>
    </div>
    <!-- 新增删除操作区域 -->
    <div class="create-container">
      <el-button type="primary" @click="addCard">添加月卡</el-button>
      <el-button @click="delMore">批量删除</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="list"  @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="100"/> 
        <el-table-column type="index" label="序号" />
        <el-table-column label="车主名称" prop="personName"/>
        <el-table-column label="联系方式" prop="phoneNumber"/>
        <el-table-column label="车牌号码" prop="carNumber"/>
        <el-table-column label="车辆品牌" prop="carBrand"/>
        <el-table-column label="剩余有效天数" prop="totalEffectiveDate"/>
        <el-table-column label="操作" fixed="right" width="180">
          <template #default="scope">
            <el-button size="mini" type="text">续费</el-button>
            <el-button size="mini" type="text">查看</el-button>
            <el-button size="mini" type="text" @click="jump(scope.row.id)">编辑</el-button>
            <el-button size="mini" type="text" @click="del(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-container" >
      <el-pagination 
        layout="total,sizes, prev, pager, next"
        :total="total"
        :current-page="params.page"
        :page-sizes="[2, 4, 6, 8,10]"
        :page-size="params.pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <!-- 添加楼宇 -->
    <el-dialog
      title="添加楼宇"
      width="580px"
    >
      <!-- 表单接口 -->
      <div class="form-container">
       
      </div>
      <template #footer>
        <el-button size="mini">取 消</el-button>
        <el-button size="mini" type="primary">确 定</el-button>
      </template>
    </el-dialog>
  </div>
</template>


<script>
  import {
    deleteCarCardAPI,
    getMonthCardListAPI
  } from '@/api/car'
export default {
  data(){
    return{
      list: [],
      total:0,
      params:{
      page: 1,
      pageSize: 2,
      carNumber:null,
      personName:null,
      cardStatus:null
    },
    paramsop:[
    {carid:1,carname:'可用',carvalue:0},
    {carid:2,carname:'已过期',carvalue:1},
    {carid:3,carname:'全部',carvalue:null}
    ]
    }
  },
  mounted() {
    
    this.getList()
  
  },

  methods:{
    handleSelectionChange(val){
      let str =''
     for(let index = 0;index < val.length;index++){
      // console.log(val[index].id);
     
      const temp = val[index]
      console.log(temp.id);
      str=str + temp.id +','

     }
   
    //  this.str =str.slice(0,str.length-1)
     const idStr = str.slice(0,str.length-1)
     this.idStr = idStr
    //  console.log(str)
    //  this.idStr =idStr
    //  console.log(this.idStr);
     },

    delMore(){
      this.$confirm('确定要删除这些月卡吗?').then(() =>{
      deleteCarCardAPI(this.idStr).then(() =>{
        this.$message.success('删除成功！')
        this.getList()
      })
     })
    },
    jump(id){
      this.$router.push('/addCard?id='+id)//跳转界面,携带参数
    },
    del(id){
      // console.log(id);
    

      this.$confirm('确认要删除吗?').then(() => {
        // console.log(1);
        deleteCarCardAPI(id).then(() => {
        this.getList()
        this.$message.success("删除成功！")
      }).catch(() => {
        this.$message.error("删除失败！")
      })

      }).catch(() => {
        // console.log(2);
      })
      
    },
    getList(){
      getMonthCardListAPI(this.params).then((res) => {
      this.list = res.data.rows
      this.total = res.data.total
      console.log(res);
    })
    },
    handleSizeChange(pageSize){
      this.params.pageSize = pageSize

     this.getList()
    },
    handleCurrentChange(page){
      this.params.page = page
      this.getList()
    },
    addCard(){
      this.$router.push('/addCard')
     
    }
  }
}
</script>


<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}


.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding-bottom: 20px;
  .search-main {
    width: 220px;
    margin-right: 10px;
  }
  .search-btn{
    margin-left:20px;
  }
}
.create-container{
  margin: 10px 0px;
}
.page-container{
  padding:4px 0px;
  text-align: right;
}
.form-container{
  padding:0px 80px;
}
</style>